package com.kantboot.business.bp.web.contrller;

import com.kantboot.business.bp.domain.dto.BusBpProblemSearchDTO;
import com.kantboot.business.bp.domain.entity.BusBpProblem;
import com.kantboot.business.bp.domain.entity.BusBpProblemAnswer;
import com.kantboot.business.bp.service.IBusBpProblemService;
import com.kantboot.util.common.result.RestResult;
import com.kantboot.util.core.param.PageParam;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/bus/bp/problem")
public class BusBpProblemController {

    @Resource
    private IBusBpProblemService service;

    /**
     * 根据id查询
     * @param id 问题的id
     * @return 实体
     */
    @RequestMapping("/getById")
    public RestResult getById(@RequestParam("id") Long id) {
        return RestResult.success(service.getById(id),"getSuccess","获取成功");
    }

    /**
     * 发布问题
     * @param busBpProblem 问题的实体
     * @return 实体
     */
    @RequestMapping("/push")
    public RestResult push(@RequestBody BusBpProblem busBpProblem) {
        return RestResult.success(service.push(busBpProblem),"pushSuccess","发布成功");
    }

    /**
     * 回答问题
     * @param entity 问题答案的实体
     * @return 实体
     */
    @RequestMapping("/answer")
    public RestResult answer(@RequestBody BusBpProblemAnswer entity) {
        return RestResult.success(service.answer(entity),"answerSuccess","回答成功");
    }

    /**
     * 获取自己的问题
     */
    @RequestMapping("/getSelfProblem")
    public RestResult getSelfProblem() {
        return RestResult.success(service.getSelfProblem(),"getSuccess","获取成功");
    }

    /**
     * 查询问题
     */
    @RequestMapping("/getBodyDataFront")
    public RestResult getBodyDataFront(@RequestBody BusBpProblemSearchDTO dto) {
        return RestResult.success(service.getBodyDataFront(dto), "getSuccess","获取成功");
    }

    /**
     * 收藏问题
     */
    @RequestMapping("/collect")
    public RestResult collect(@RequestParam("id") Long id) {
        service.collect(id);
        return RestResult.success(null,"collectSuccess","收藏成功");
    }

    /**
     * 取消收藏问题
     */
    @RequestMapping("/cancelCollect")
    public RestResult cancelCollect(@RequestParam("id") Long id) {
        service.cancelCollect(id);
        return RestResult.success(null,"cancelCollectSuccess","取消收藏成功");
    }

    /**
     * 获取自己的收藏
     */
    @RequestMapping("/getSelfCollection")
    public RestResult getSelfCollection() {
        return RestResult.success(service.getSelfCollection(),"getSelfCollectionSuccess","获取自己的收藏成功");
    }

    /**
     * 认可答案
     */
    @RequestMapping("/recognizedAnswer")
    public RestResult recognizedAnswer(@RequestParam("id") Long id) {
        service.recognizedAnswer(id);
        return RestResult.success(null,"recognizedAnswerSuccess","认可答案成功");
    }

    /**
     * 获取所有答案
     */
    @RequestMapping("/getBodyData")
    public RestResult getBodyData(@RequestBody PageParam<BusBpProblemSearchDTO> dto) {
        return RestResult.success(service.getBodyData(dto),"getSuccess","获取成功");
    }

}
